//服务器端
#include "comm.h"
using namespace std;

int main()
{
    //创建命名管道文件
    if(mkfifo(IPC_PATH,0600)!=0)
    {
        cerr<<"fifo error"<<endl;
        exit(1);
    }
    //打开文件
    int pipefd = open(IPC_PATH,O_RDONLY);
    //读取数据
    char line[NUM];
    while(1)
    {
        int dia = read(pipefd,line,NUM);
        if(dia>0)
        {
            line[dia]='\0';
            cout<<"pid: "<<getpid()<<" 服务器端 读取："<<line<<endl;
        }
        else if(dia==0)
        {
            cout<<"读取结束"<<endl;
            break;
        }
        else
        {
            //do nothing
        }
    }
    close(pipefd);
    unlink(IPC_PATH);
    return 0;
}